<!--
 * @Author: gao_m3
 * @Date: 2020-09-03 08:52:51
 * @LastEditors: zhong_m
 * @LastEditTime: 2021-12-20 13:59:23
 * @Descripttion: 开发者模式页
-->
<template>
  <div v-popover:lang class="right-menu-item">
    <fks-popover
      ref="lang"
      trigger="click"
      placement="bottom"
      :visible-arrow="false"
      popper-class="toolbar-popover"
    >
      <span
        slot="reference"
        style="font-size: 14px; color: #368bff; cursor: pointer"
      >
        {{ LANG.DEVELOPER_MODE }}
        <i
          class="fks-icon-caret-bottom"
          style="margin-left: 4px; color: #333"
        />
      </span>
      <div class="language-select">
        <ul class="language-select-options">
          <li
            v-for="mode in modes"
            :key="mode.value"
            @click="handleCommand(mode)"
          >
            <span style="font-size: 14px; color: black; cursor: pointer">{{
              mode.label
            }}</span>
          </li>
        </ul>
      </div>
    </fks-popover>
  </div>
</template>

<script>
import { getClientCatch, getUserCatch, getUserPermission } from '@/api/app'
export default {
  name: 'Developers',
  prop: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      currentLang: ''
    }
  },
  computed: {
    modes() {
      return [
        { value: 'SyncUserCache', label: this.LANG.SYNC_USER_CACHE },
        { value: 'SyncUserPermission', label: this.LANG.SYNC_USER_PERMISSION },
        { value: 'SyncClientCache', label: this.LANG.SYNC_CLIENT_CACHE },
        { value: 'close', label: this.LANG.CLOSE_DEVELOPER_MODE }
      ]
    }
  },
  methods: {
    //下拉菜单
    handleCommand(data) {
      switch (data.value) {
        case 'SyncClientCache': {
          getClientCatch().then((res) => {
            if (res.status) {
              this.$message.success(this.LANG.SYNC_CLIENT_CACHE_SUCCESS)
            }
          })
          break
        }
        case 'SyncUserCache': {
          getUserCatch().then((res) => {
            if (res.status) {
              this.$message.success(this.LANG.SYNC_USER_CACHE_SUCCESS)
            }
          })
          break
        }
        case 'SyncUserPermission': {
          getUserPermission().then((res) => {
            if (res.status) {
              this.$message.success(this.LANG.SYNC_USER_PERMISSION_SUCCESS)
            }
          })
          break
        }
        case 'close': {
          this.$emit('closeMode')
          this.$message.success(this.LANG.CLOSE_DEVELOPER_MODE_SUCCESS)
          break
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .fks-icon-caret-bottom::before {
  color: #368bff;
}

.language-select {
  &-title {
    padding: 0 0 8px;
    border-bottom: 1px solid #f2f3f4;
    font-weight: bold;
    text-align: center;
    color: #393e45;
  }

  &-options {
    padding: 0;

    li {
      padding: 4px 0;
      font-size: 0;
      text-align: center;
      cursor: pointer;

      &:hover {
        background-color: #f7f8f8;
      }
    }

    li + li {
      margin-top: 5px;
    }

    .language {
      margin-right: 10px;
      font-size: 0;
    }

    span {
      font-size: 14px;
      vertical-align: middle;
      color: #999;
    }
  }
}
</style>